package model;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

import vista.Vista;

public class FluxoEntrada extends Thread{

	private Socket socket;
	private BufferedReader inFromServer;
	private Vista vista;
	private String sentence;
	
	public FluxoEntrada(Socket socket,Vista vista){
		this.vista=vista;
		try{
			this.inFromServer=new BufferedReader(new InputStreamReader(socket.getInputStream()));
		}catch(IOException ioe){}
	}
	
	public BufferedReader getInFromServer() {
		return this.inFromServer;
	}
	
	public void run(){
		while(true){
			try{
				this.sentence=inFromServer.readLine();
				this.vista.getTextArea().setText(vista.getTextArea().getText()+sentence+'\n');
			}catch(IOException e){}
			this.vista.getJanela().repaint();
		}
	}
	
	public void fecharConexao(){
		try{
			this.socket.close();
		}catch(IOException ioe){}
	}
}
